package com.x.chat.service;

import com.x.chat.dao.ChatDao;
import com.x.chat.model.Chat;
import com.x.chat.pojo.ChatItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ChatService {
    @Autowired
    private ChatDao chatDao;

    @Autowired
    private WebSocketService webSocketService;

    public void addChat(ChatItem rcvChatItem) {
        Chat chat = new Chat(-1, rcvChatItem.getSenderId(), rcvChatItem.getReceiverId(), 1, rcvChatItem.getOrigin(), rcvChatItem.getType(), rcvChatItem.getSrc(), null);
//        chatDao.addChat(chat);

        // 寻找对象的websocket
        webSocketService.sencMessageToUser(rcvChatItem.getSenderId(), rcvChatItem);
        webSocketService.sencMessageToUser(rcvChatItem.getReceiverId(), rcvChatItem);
    }
}
